<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<script src="../js/vue.js"></script>
<script src="../js/axios.js"></script>
<script src="../js/util.js"></script>
<body>

    <div id="app">
        <button @click="add()" type="button">添加</button>
        姓名：<input type="text" v-model="name">
        <input type="button" value="搜索" @click="findPage(1)">
        <table border="1" cellspacing="0">
            <tr>
                <td>ID</td>
                <td>姓名</td>
                <td>年龄</td>
                <td>地址</td>
                <td>操作</td>
            </tr>
            <tr v-for="emp in page.records">
                <td>{{emp.id}}</td>
                <td>{{emp.name}}</td>
                <td>{{emp.age}}</td>
                <td>{{emp.address}}</td>
                <td>
                    <button type="button" @click="del(emp.id)">删除</button>
                </td>
            </tr>
        </table>
        <a @click="findPage(1)">首页</a>
        <a @click="findPage(page.current-1)">上一页</a>
        <a @click="findPage(page.current+1)">下一页</a>
        <a @click="findPage(page.pages)">尾页</a>
    </div>
</body>
<script>
    new Vue({
        el:"#app",
        data:{
            page:{},
            name:""
        },
        created(){
            this.findPage(1)
        },
        methods:{
            findPage(pageIndex){
                axios.post("/order/findPage?pageIndex="+pageIndex+"&name="+this.name).then(
                    res=>{
                        this.page = res.data
                    }
                )
            },
            add(){
                location.href="add.html";
            },
            del(id){
                axios.get("/order/del?id="+id).then(
                    res =>{
                        location.href="emp.html"
                    }
                )
            }
        }
    })
</script>
</html>